package org.dreamland.infrastructure.security

import jakarta.servlet.http.HttpServletRequest
import jakarta.servlet.http.HttpServletResponse
import org.springframework.session.web.http.HttpSessionIdResolver

class MultipleSessionIdResolver: HttpSessionIdResolver
{
    private val items = mutableListOf<HttpSessionIdResolver>()

    fun addHttpSessionResolver(httpSessionIdResolver: HttpSessionIdResolver) {
        items.add(httpSessionIdResolver)
    }

    override fun resolveSessionIds(request: HttpServletRequest?): MutableList<String> {

        return items.map { it.resolveSessionIds(request) }.first()
    }

    override fun setSessionId(request: HttpServletRequest?, response: HttpServletResponse?, sessionId: String?) {
         items.forEach { it.setSessionId(request, response, sessionId) }
    }

    override fun expireSession(request: HttpServletRequest?, response: HttpServletResponse?) {
        items.forEach { it.expireSession(request, response) }
    }
}